package cred

import (
	"github.com/shima-park/agollo"
	"google.golang.org/grpc"
	"google.golang.org/grpc/credentials"
	"log"
)

// TLSInterceptor TLS证书认证
func TLSInterceptor() grpc.ServerOption {
	SecretPemPath := ""
	NamespaceSecret := ""
	SecretKeyPath := ""

	pemPath := agollo.Get(SecretPemPath, agollo.WithNamespace(NamespaceSecret))
	keyPath := agollo.Get(SecretKeyPath, agollo.WithNamespace(NamespaceSecret))
	// 从输入证书文件和密钥文件为服务端构造TLS凭证
	creds, err := credentials.NewServerTLSFromFile(pemPath, keyPath)
	if err != nil {
		log.Fatalf("Failed to generate credentials %v", err)
	}
	return grpc.Creds(creds)
}
